﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
using System.Net;
using System.ServiceProcess;
using System.Threading;
using System.Xml.Linq;


namespace ReserveMeService
{
    public partial class ReserveMeService : ServiceBase
    {
        private Base b;
        private Timer workTimer;

        public ReserveMeService()
        {            
            InitializeComponent();
        }


        protected override void OnStart(string[] args)
        {
            workTimer = new Timer(new TimerCallback(monitorBase), null, 5000, 60000);                   
        }

        private void monitorBase(object state)
        {
            if (b == null)
            {
                b = new Base();
                b.start();
            }
            else
            {              
                b.start();
            }
        }

        protected override void OnStop()
        {
            if (b != null)
            {
                b.close();
                workTimer.Dispose();
            }
            else
            {
                workTimer.Dispose();
            }
        }      
    }
}
